# IRCII Trivia Script v1.1.0 # Copyright (c) 2001-2002 Bernard Yen (Seeker on IRC) # -------------------------------------------------------------------------- # This software is provided 'as-is', without any expressed or implied # warrenty. In no event will the author be held liable for any damages # arising from the use of this software. # # Permissing is granted to anyone to use this software for non-commercial # purposes and to alter and redistribute it freely, subject to the # following restrictions: # # 1. The origin of this software must not be misrepresented; you must not # claim that you wrote the original software. If you use this software in # a product, an acknowledgement in the product documentation is required. # # 2. Altered source versions must be plainly marked as such, and must not # be misrepresented as being the original software # # 3. This notice may not be removed or altered from any source distribution. # -------------------------------------------------------------------------- # --- Program Constant Declarations --- # Limit on how long each question is posed for in seconds @trivia.LIMIT.1 = 50 @trivia.LIMIT.2 = 50 @trivia.LIMIT.3 = 45 @trivia.LIMIT.4 = 45 @trivia.LIMIT.5 = 40 # Number of seconds to pause between questions @trivia.BREAK = 20 # Number of seconds before a duel is called off @trivia.DUELSTOPTIME = 30 # Level of duelling question to ask @trivia.DUELLEVEL = 3 # Number of seconds to wait before a duel is tied (no one answers correct) @trivia.DUELQUESTIME = 45 # Fraction of points lost during a duel (1/trivia.DUELFRAC) @trivia.DUELFRAC = 3 # Minimum amount of points to participate in a duel @trivia.DUELMIN = 5 # Minimum amount of seconds to wait before a person can duel again @trivia.DUELREST = 30 # Number of seconds to pause between final score and start of wagering. Note that # the actual time between display of score and wagering start is WAGERWAIT - BREAK # since both timers are started at the same time. @trivia.WAGERWAIT = 30 # Number of seconds to pause between start of wagering and end of wagering. @trivia.WAGERTIME = 60 # Number of rounds available in one game, excluding wagering round. @trivia.MAXROUND = 4 # Number of questions for each round. Last round must have exactly 1 question. @trivia.QU.1 = 5 @trivia.QU.2 = 5 @trivia.QU.3 = 5 @trivia.QU.4 = 5 @trivia.QU.5 = 1 # Maximum number of daily double questions per round. @trivia.SUDDENDEATH = 3 # Probability of daily double questions appearing (1/PROBDEATH). @trivia.PROBDEATH = 8 # Proportion of regular round's point to take off if player gets daily double questions wrong. # The final penalty is (round's point)/trivia.PENALTYDEATH. Note that decimals are rounded down. @trivia.PENALTYDEATH = 2 # Proportion of regular round's point to give to player if they get daily double questions right. # The final award is (round's point)*trivia.AWARDDEATH. @trivia.AWARDDEATH = 2 # Amount of points awarded for each round. Last round is 0 points since it is the wagering # round, and people cannot obtain additional points for getting it right. @trivia.P.1 = 2 @trivia.P.2 = 4 @trivia.P.3 = 6 @trivia.P.4 = 8 @trivia.P.5 = 0 # Amount of bonus point awarded for first person answering correctly. @trivia.BONUSVALUE = 1 # Administrative password -- required for all admin commands. @trivia.ADMINPASS = [default] # Valid commands that can be sent to the bot. @trivia.VALIDCMD = [!start !stop !reset !add !sub !load_s !load_q !wipe !save !duel !acc !ans !auth !unauth !change_pass !convert !title !title_kill] # Valid admin commands that can be sent to the bot. @trivia.VALIDADMINCMD = [!start !stop !reset !add !sub !load_s !load_q !wipe !save] # Weight of penalty points. A weight of X would mean the player gets penalized WRONG/X at the # end of the game where WRONG is the number of wrong answers. Note that decimals are rounded down. @trivia.PENALTYWEIGHT = 5 # Rank above which player can create their own title. @trivia.MAXRANK = 1000 # People that cannot be duelled with. The nickname of the bot should be included here. @trivia.NODUEL = [ChanServ TriviaBot] # People who have helped on this project and deserves special mention. @trivia.THANKYOU = [chibi_k, dunno001, Hisoka, InuTrunks, IPChan, Klepto, Knotz, lego, Mike-hime, melz, NFD, Teppei, XObadboy, xxloloxx] # Version of the trivia script. @trivia.VERSION = [1.1.0] # --- PurePak Constants --- @ PP.SET.RMCMD = [rm -f] @ PP.SAVEFILE = [trivia.sav] @ HOME = [:UserScripts] # --- Channel Name --- @trivia.channel = [Snak] # --- Global Variables --- # People who have answered the current question correctly @trivia.curques = [] # Display variable for people who answered the current question correctly @trivia.curqueslist = [] # Flag indicating whether a game is running (0:NO, 1:YES) @trivia.current = 0 # Current trivia round number @trivia.round = 0 # Questions remaining in current round @trivia.remaining = 0 # Question number of current round being asked @trivia.quesnum = 0 # Index for the encoding player score variables @trivia.index = 0 # Flag indicating whether there is a question being shown right now @trivia.active = 0 # A list of all used questions since the robot has been started @trivia.usedques = [] # List of wrong answers submitted for current question @trivia.wrong = [] # Flag indicating whether bonus points are given @trivia.bonus = 0 # Flag indicating whether wagering is allowed @trivia.wager = 0 # Flag to fix problems with the compare function during wagering @trivia.wager_special = 0 # Count of the number of sudden death questions which has appeared @trivia.amtdeath = 0 # Flag indicating whether current question is a sudden death question @trivia.deathflag = 0 # Flag indicating whether the question list is loaded @trivia.qloaded = 0 # Flag indicating whether there is a duel waiting to be accepted @trivia.duelwait = 0 # Flag indicating that the duel victim has accepted the aggressor's challenge @trivia.duelstart = 0 # Name of the duel aggressor @trivia.duelagg = [] # Name of the duel victim @trivia.duelvictim = [] # Players who answered the current duel question correctly @trivia.duelrightlist = [] # A question timer to display how fast the players responds to the question @trivia.timer = 0 # Players who are currently resting from a duel (i.e. cannot issue duel) @trivia.duelrestlist = [] # --- Start of program code. Do not modify anything below this line. --- alias trivia { # Load the auxilary question file into memory if not loaded yet. if (!trivia.qloaded) { $loadq() } # Load the saved variables from file. if (!trivia.stat_loaded) { /load $PP.SAVEFILE } # Check whether we need to reset the score of the day, week, and month. @trivia.dummvar = update_high() # Check whether a game is currently running. Give an error if there is. if (trivia.current == 0) { @trivia.current = 1 # Print out the trivia header (copyright, thank you note, trivia record holder) ^say $trivia.channel Trivia v$trivia.VERSION Copyright 2002 by 5Seeker ^say Special Thanks: $trivia.THANKYOU ^say if (!trivia.bestscore || trivia.bestscore == 0) { ^say Highest Trivia Record:5 None @4 0 point } { if (trivia.bestscore == 1) { ^say Highest Trivia Record:5 $trivia.bestname @4 1 point } { ^say Highest Trivia Record:5 $trivia.bestname @4 $trivia.bestscore points } } ^say # Initialize the randomizer, clear global variables, and show the first question. @trivia.correct = 0 @trivia.round = 0 @trivia.remaining = 0 @trivia.quesnum = 0 @trivia.index = 0 @trivia.remaining = 0 @trivia.active = 0 @trivia.wager = 0 @trivia.wager_special = 0 @trivia.amtdeath = 0 @trivia.deathflag = 0 @trivia.randomvar = trivia.randomvar + 1 @trivia.seed = [$time()] + trivia.randomvar $srand($trivia.seed) $show_question() } { ^say [ERROR] Please wait until the current game ends before starting another } } # Load or reload the question into memory so it can be used by this script. alias loadq { ^load trivia_question ^load trivia_taunt } # Show a question based on the round number. Higher rounds are more difficult. $0 controls whether the # wagering round is on (0:NO, 1:YES). alias show_question { # Clear global variables. @trivia.curques = [] @trivia.curqueslist = [] @trivia.wrong = [] # If no more questions available in this round, move to next round and reset question number. if (!trivia.remaining) { @trivia.quesnum = 1 @trivia.round= trivia.round + 1 @trivia.remaining = trivia[QU][$trivia.round] } { @trivia.quesnum = trivia.quesnum + 1 } # Set expiration timer for current question. If we are in wagering round, queue up $calc_wager to be called. if ([$0] == 1) { ^timer -refnum 1 $trivia[LIMIT][$trivia.round] /calc_wager } { ^timer -refnum 1 $trivia[LIMIT][$trivia.round] /stop } # Find the maximum number of question available on the current difficulty level and choose # one of them. If the question has been posed already, choose another one. @trivia.catques = trivia[C][$trivia.round] @trivia.pick = rand($trivia.catques) + 1 while ([$match($trivia.round*$trivia.pick $trivia.usedques)]) { @trivia.pick = rand($trivia.catques) + 1 } # Add question to used question list (format round*quesnum) ^assign trivia.usedques $trivia.usedques $trivia.round*$trivia.pick ^assign trivia.temp $trivia[A][$trivia.round][$trivia.pick] ^assign trivia.temp $#trivia.temp # Potentially make this question a daily double question, but the wagering round cannot # be turned into a daily double, so additional checks are done. If the question turns out # to be a daily double, we increment $trivia.amtdeath by 1 to keep track. @trivia.deathflag = 0 if ((trivia.amtdeath < trivia.SUDDENDEATH) && (trivia.round <= trivia.MAXROUND)) { if (rand($trivia.PROBDEATH) == 0) { @trivia.deathflag = 1 @trivia.amtdeath = trivia.amtdeath + 1 } } if (!trivia.deathflag) { ^say === Round $trivia.round Question $trivia.quesnum >> Time Limit: $trivia[LIMIT][$trivia.round] seconds === } { ^say === Round $trivia.round Question $trivia.quesnum >> Time Limit: $trivia[LIMIT][$trivia.round] seconds [DAILY DOUBLE] === } # If the answer is a number (i.e. trivia.Q.R.P.N is defined), don't print out the number of words # so people are not confused. if (trivia[Q][$trivia.round][$trivia.pick][N]) { ^say [4Q] 3$trivia[Q][$trivia.round][$trivia.pick] \ } { if (trivia.temp == 1) { ^say [4Q] 3$trivia[Q][$trivia.round][$trivia.pick] \<$trivia.temp word\> } { ^say [4Q] 3$trivia[Q][$trivia.round][$trivia.pick] \<$trivia.temp words\> } } # Start the timer so we can record down how fast the players answer the question. Also # activate the trivia.active flag to indicate that there is an active question. @trivia.timer = time() @trivia.active = 1 } # Respond to trivia answers sent through private message. Calls $check_active() to see whether # a question is currently being shown. $check_active() will also filter out commands and # execute them. on -msg "* *" { $check_active($0 $1-) } # This function parses messages that the bot may receive. It processes both commands which begin # with a "!" and regular answers. If there are no active question, all msgs are treated as regular # text which is not processed (except commands, which are still processed). alias check_active { # Parsing of wagering messages. if (trivia.wager && word(0 $1-) == [!wager]) { # Check to make sure there is a valid wager, meaning $2 exist and is a positive integer. We also # check whether the player has enough points. @trivia.temp = strip(abcdefghijklmnopqrstuvwxyz. $tolower($2)) if (!trivia.temp || trivia.temp <= 0 || trivia.temp > trivia[$encode($0)]) { ^notice $0 [ERROR] Command is !wager where amount > 0 but < your score. } { if (trivia.temp == 1) { ^notice $0 You have chosen to wager5 $trivia.temp point. } { ^notice $0 You have chosen to wager5 $trivia.temp points. } # This is a validated wager, so go ahead and place it (exits function). $putwager($0 $trivia.temp) } } # Determine whether they are messaging a valid command. If so, go to command parsing. # Otherwise, go to message parsing. if (match($word(0 $1-) $trivia.VALIDCMD)) { $cmd_parse($0 $1-) } { if (!trivia.active) { # Normal private message, don't do anything. } { # If it is the wagering round but they don't have points, they are not allowed to answer. if ((trivia.round == (trivia.MAXROUND + 1)) && !trivia[$encode($0)]) { ^notice $0 [ERROR] You need at least 1 point to answer in the wagering round. } { # Check whether the submitted answer is a fun answer or a real answer. If it is just # a fun answer, a special routine is called to process it. if (word(0 $1-) == [!fun]) { $handle_fun($0 $2-) } { $compare($0 $1-) } } } } } # Handles commands embedded in the incoming private messages. If the command requires special # authorization, this function checks the admin password before passing the command on to # $parse_admin(). alias cmd_parse { # !duel, !acc, and !duel_ans are used for the duelling system. if (word(0 $1-) == [!duel]) { if (!word(1 $1-)) { ^notice $0 [ERROR] Command is !duel where nick is the person you want to duel. } { ^timer 1 /duel $0 $word(1 $1-) } } if (word(0 $1-) == [!acc]) { ^timer 1 /accept_duel $0 } if (word(0 $1-) == [!ans]) { if (!word(1 $1-)) { ^notice $0 [ERROR] Command is !ans where ans is your answer. } { ^timer 1 /duel_ans $0 $1- } } # !convert, !auth, !title, !title_kill, and !change_pass are used for the personal stat system. if (word(0 $1-) == [!convert]) { if (!word(1 $1-) || !word(2 $1-)) { ^notice $0 [ERROR] Command is !convert . } { ^timer 1 /check_conv $0 $word(1 $1-) $word(2 $1-) } } if (word(0 $1-) == [!auth]) { if (!word(1 $1-)) { ^notice $0 [ERROR] Command is !auth . } { ^timer 1 /check_auth $0 $word(1 $1-) } } if (word(0 $1-) == [!unauth]) { ^timer 1 /deauth $0 } if (word(0 $1-) == [!change_pass]) { if (!word(1 $1-) || !word(2 $1-)) { ^notice $0 [ERROR] Command is !change_pass . } { ^timer 1 /change_pass $0 $word(1 $1-) $word(2 $1-) } } if (word(0 $1-) == [!title]) { @trivia.tempnet = trivia[RIGHT][$encode($0)] - trivia[WRONG][$encode($0)] / trivia.PENALTYWEIGHT if (trivia.tempnet < trivia.MAXRANK) { ^notice $0 [ERROR] Sorry, but your rank is not high enough to use this command. } { if (!word(1 $1-)) { ^notice $0 [ERROR] Command is !title . } { ^timer 1 /change_title $0 $2- } } } if (word(0 $1-) == [!title_kill]) { if (trivia[SELF_TITLE][$encode($0)] != []) { ^assign -trivia[SELF_TITLE][$encode($0)] ^notice $0 Your customized title has been successfully removed. } { ^notice $0 [ERROR] Sorry, but you do not have a customized title to delete. } } # !start, !stop, !reset, !add, !sub, !load_s, !load_q, !wipe are admin cmds which require the # admin password. Do not put non-admin commands below here becaues the admin password is # checked at this point. Normal commands will fail. if (!match($word(0 $1-) $trivia.VALIDADMINCMD)) { # Don't do anything since this is not an admin command. } { if (word(1 $1-) != trivia.ADMINPASS) { ^notice $0 [ERROR] The admin password you provided is not correct. } { $parse_admin($0 $1-) } } } # Changes the title of an individual player. This function is assumed only accessible after a # player achieves the minimum rank of trivia.MAXRANK. alias change_title { ^assign trivia[SELF_TITLE][$encode($0)] $1- ^notice $0 Your title has been successfully changed. } # Handles the parsing of admin commands. This function assumes that when it is being called, the # admin password has already been verified. alias parse_admin { if (word(0 $1-) == [!start]) { ^timer 1 /trivia } if (word(0 $1-) == [!stop]) { /endtrivia } if (word(0 $1-) == [!reset]) { ^timer 1 /reset_used $0 } if (word(0 $1-) == [!wipe]) { if (!word(2 $1-)) { ^notice $0 [ERROR] Command is !wipe . } { ^timer 1 /wipe_stat $0 $word(2 $1-) } } if (word(0 $1-) == [!save]) { /sve ^notice $0 The current game stats have been saved. } if (word(0 $1-) == [!add]) { if (!word(2 $1-) || !word(3 $1-)) { ^notice $0 [ERROR] Command is !add . } { ^assign trivia.tempmsg $0 ^assign trivia.temppts $word(3 $1-) ^userhost $word(2 $1-) -cmd ^assign trivia.tempadd $$0 ^userhost $word(2 $1-) -cmd if ([$3]){ ^timer 1 /add_score $trivia.tempmsg $trivia.tempadd $trivia.temppts } { ^notice $trivia.tempmsg [ERROR] Player does not exist on the IRC server. } } } if (word(0 $1-) == [!sub]) { if (!word(2 $1-) || !word(3 $1-)) { ^notice $0 [ERROR] Command is !sub . } { ^assign trivia.tempmsg $0 ^assign trivia.temppts $word(3 $1-) ^userhost $word(2 $1-) -cmd ^assign trivia.tempadd $$0 ^userhost $word(2 $1-) -cmd if ([$3]){ ^timer 1 /sub_score $trivia.tempmsg $trivia.tempadd $trivia.temppts } { ^notice $trivia.tempmsg [ERROR] Player does not exist on the IRC server. } } } if (word(0 $1-) == [!load_s]) { ^timer 1 /reload $0 } if (word(0 $1-) == [!load_q]) { ^timer 1 /loadq } } # Completely wipes a player's personal stat database. The first parameter is the person who invoked # this function, and the second parameter is the nickname to wipe. alias wipe_stat { # Load the stat file if not loaded yet. if (!trivia.stat_loaded) { /load $PP.SAVEFILE } # Check to see if person being wiped exists if (!trivia[PASS][$encode($1)]) { ^notice $0 [ERROR] The player you are trying to wipe does not exist. } { # Don't let admins wipe stat during a game, or else weird things might happen. if (trivia.current) { ^notice $0 [ERROR] You cannot use the !wipe command when a game is running. } { ^assign -trivia[PASS][$encode($1)] ^assign -trivia[RIGHT][$encode($1)] ^assign -trivia[WRONG][$encode($1)] ^assign -trivia[DUEL_WIN][$encode($1)] ^assign -trivia[DUEL_LOSE][$encode($1)] ^assign -trivia[GAME_WON][$encode($1)] ^notice $0 $1's personal stat database has been successfully wiped. } } } # Handles humorous answer submission. Critera for a valid answer include player not having submitted # a previous wrong answer. They are allowed to add a humorous answer even if they answered the question # correct already. alias handle_fun { if (![$match($0 $trivia.wrong)] && ![$match($0, $trivia.wrong)]) { $append_answer($0 $1-) ^notice $0 Your fun answer has been added successfully. } { ^notice $0 [ERROR] You have already submitted a fun or wrong answer. } } # Reload the trivia script. alias reload { ^load trivia ^notice $0 The trivia script has been successfully reloaded. } # Increase the score of player $1 by $2 points. alias add_score { @trivia.temp = [$2] if (trivia[$encode($1)]) { @trivia[$encode($1)] = trivia[$encode($1)] + trivia.temp } { @trivia[$encode($1)] = trivia.temp @trivia.dummy = addtolist($1 0) } ^notice $0 $1's score has been successfully changed. } # Decrease the score of player $0 by $1 points. alias sub_score { @trivia.temp = [$2] @trivia[$encode($1)] = trivia[$encode($1)] - trivia.temp ^notice $0 $1's score has been successfully changed. } # Place the wager for the player by assigning it to $trivia[$encode($0)][WAGER]. alias putwager { @trivia[$encode($0)][WAGER] = [$1] } # Because the normal match procedure only matches one word, the match_all procedure is used # to match all words. Based on whether this is a duel question, we either match against the # normal answer or the duel answer (0: NORMAL, 1: DUEL). alias match_all { @trivia.counter = 0 @function_return = 1 # Determine which answer to use if ([$0] == 0) { @trivia.temp = trivia[A][$trivia.round][$trivia.pick] } { @trivia.temp = trivia[A][$trivia.DUELLEVEL][$trivia.duelpick] } while (trivia.counter < [$#trivia.temp]) { # Perform some generic pattern matching with pluaral and non-plural words. @trivia.tempword = word($trivia.counter $trivia.temp) if (right(1 $trivia.tempword) == [s] && right(3 $trivia.tempword) != [ies]) { @trivia.tempword2 = left(${@trivia.tempword - 1} $trivia.tempword) } { if (right(1 $trivia.tempword) == [y]) { @trivia.tempword2 = left(${@trivia.tempword - 1} $trivia.tempword)##[ies] } { if (right(3 $trivia.tempword) == [ies]) { @trivia.tempword2 = left(${@trivia.tempword - 3} $trivia.tempword)##[y] } { @trivia.tempword2 = trivia.tempword##[s] } } } # Perform some common typo matching between 'e' and 'i', 'l' and 'r', 'k' and 'c', 'j' and 'z', 'h' and 'u', 'o' and 'u'. @trivia.guessn1 = strip(ei $1-) @trivia.guessn2 = strip(lr $1-) @trivia.guessn3 = strip(kc $1-) @trivia.guessn4 = strip(jz $1-) @trivia.guessn5 = strip(hu $1-) @trivia.guessn6 = strip(ou $1-) @trivia.ansn1 = strip(ei $trivia.tempword) @trivia.ansn2 = strip(lr $trivia.tempword) @trivia.ansn3 = strip(kc $trivia.tempword) @trivia.ansn4 = strip(jz $trivia.tempword) @trivia.ansn5 = strip(hu $trivia.tempword) @trivia.ansn6 = strip(ou $trivia.tempword) if (![$match($trivia.tempword $1-)] && ![$match($trivia.tempword2 $1-)] && ![$match($trivia.ansn1 $trivia.guessn1)] && ![$match($trivia.ansn2 $trivia.guessn2)] && ![$match($trivia.ansn3 $trivia.guessn3)] && ![$match($trivia.ansn4 $trivia.guessn4)] && ![$match($trivia.ansn5 $trivia.guessn5)] && ![$match($trivia.ansn6 $trivia.guessn6)]) { @function_return = 0 } @trivia.counter = trivia.counter + 1 } } # Display the bonus message when players get a question correct first. Sudden death questions # give a certain multiple of the normal points. alias display_bonus { @function_return = 1 if (trivia.deathflag) { @trivia.temp = trivia.AWARDDEATH * trivia.BONUSVALUE ^notice $0 For getting it correct first, you get5 $trivia.temp extra bonus points. } { if (trivia.BONUSVALUE == 1) { ^notice $0 For getting it correct first, you get5 $trivia.BONUSVALUE extra bonus point } { ^notice $0 For getting it correct first, you get5 $trivia.BONUSVALUE extra bonus points } } } # Add the player to the list of participants. $1 denotes whether to initialized the player's # score to 0 (0:NO, 1:YES). alias addtolist { @function_return = 1 @trivia[rec][$trivia.index] = encode($0) @trivia.index = trivia.index + 1 @trivia[$encode($0)][LIST] = 1 if ([$1] == 1) { @trivia[$encode($0)] = 0 } } # Calculate the amount of points awarded to a player. $0 denotes whether a bonus value should # be added during the computation (0:NO, 1:YES). alias calcpoint { if ([$0] == 1) { @function_return = trivia[P][$trivia.round] + trivia.BONUSVALUE } { @function_return = trivia[P][$trivia.round] } } # Displays the timer on the correct answer list. alias timer_display { @function_return = 1 @trivia.temptime = time() - trivia.timer if (!trivia.curqueslist) { ^assign trivia.curqueslist $0 5\[$trivia.temptime sec\] } { ^assign trivia.curqueslist $trivia.curqueslist, $0 5\[$trivia.temptime sec\] } } # Given the question number, this compares the inputted answer with the correct answer # using pattern matching. This function also performs score keeping. alias compare { @trivia.bonus = 0 @trivia.finalscore = 0 @trivia.correct = match_all(0 $1-) # If correct answer and they have not answered already. if (trivia.correct && ![$match($0 $trivia.curques)]) { @trivia.dummvar = auth_help($0 0) ^notice $0 You answered the question correctly. Congratulations! # First person to answer the question correct gets 1 bonus point, but only when it's not in the # wagering round. If we are in sudden death round, we display twice the normal bonus point. if (!trivia.curques) { if (!trivia.wager_special) { @trivia.bonus = 1 @trivia.dummy = display_bonus($0) } } # Assign person to people who have already answered the current question correctly. ^assign trivia.curques $trivia.curques $0 # Add person to the list to print out containing people who answered question correctly. @trivia.dummvar = timer_display($0) # Initiate a personal score variable. We must encode the text since some of the # characters in a nickname cannot be part of a variable. If the variable already exists # then add the scores on. We also add the encoded text to a global list so we can remove # all the variables in the end. ^assign trivia.finalscore $calcpoint($trivia.bonus) # If the question is sudden death, increase the score the player receive, include the bonus # points incurred. if (trivia.deathflag) { @trivia[$encode($0)] = trivia[$encode($0)] + trivia.AWARDDEATH * trivia.finalscore } { @trivia[$encode($0)] = trivia[$encode($0)] + trivia.finalscore } if (!trivia[$encode($0)][LIST]) { @trivia.dummy = addtolist($0 0) } # We know they are added on the $trivia[rec] list at this point. Know we check whether they # got the answer correct by submitting multiple answers on one line. @trivia.temp1 = [$1-] @trivia.temp2 = trivia[A][$trivia.round][$trivia.pick] @trivia.temp1 = [$#trivia.temp1] @trivia.temp2 = [$#trivia.temp2] if (trivia.deathflag) { if (trivia.temp1 > trivia.temp2) { # Multiplication by trivia.PENALTYWEIGHT since each penalty point is worth X number # of wrong answers where X = trivia.PENALTYWEIGHT. @trivia.penalty = trivia.PENALTYWEIGHT*trivia[P][$trivia.round]/trivia.PENALTYDEATH @trivia[$encode($0)][WRONG] = trivia[$encode($0)][WRONG] + trivia.penalty @trivia.dummvar = auth_help($0 4 $trivia.penalty) } } { if (trivia.temp1 > trivia.temp2) { @trivia.penalty = trivia.temp1/trivia.temp2 - 1 @trivia[$encode($0)][WRONG] = trivia[$encode($0)][WRONG] + trivia.penalty @trivia.dummvar = auth_help($0 4 $trivia.penalty) } } } { # If they answered the question already, or if the answer is incorrect. if ([$match($0 $trivia.curques)]) { ^notice $0 [ERROR] You have already answered this trivia question! } { # If the person has penalty point but is not on record, it's not good. Add them in so we # can delete the variable in the end of the game. if (!trivia[$encode($0)][LIST]) { @trivia.dummy = addtolist($0 1) } # Increment the number of wrong answers they've submitted. This is weighted by # the length of the current answer to make the process fair. The assignments are done # twice so the correct value can be stored. @trivia.temp1 = [$1-] @trivia.temp2 = trivia[A][$trivia.round][$trivia.pick] @trivia.temp1 = [$#trivia.temp1] @trivia.temp2 = [$#trivia.temp2] # Multiplication by trivia.PENALTYWEIGHT since each penalty point is worth X number # of wrong answers where X = trivia.PENALTYWEIGHT. if (trivia.deathflag) { @trivia.penalty = trivia.PENALTYWEIGHT*trivia[P][$trivia.round]/trivia.PENALTYDEATH } { @trivia.penalty = trivia.temp1/trivia.temp2 } @trivia[$encode($0)][WRONG] = trivia[$encode($0)][WRONG] + trivia.penalty @trivia.dummvar = auth_help($0 4 $trivia.penalty) ^notice $0 Sorry, but your answer is not correct. # Add the wrong answer to a list so we can print it out, but only one per person. if (![$match($0 $trivia.wrong)]) { $append_answer($0 $1-) } } } } # Add a wrong answer to a $trivia.wrong so they can be printed out when the game ends. alias append_answer { if (!trivia.wrong) { ^assign trivia.wrong $0 \[$1-\] } { ^assign trivia.wrong $trivia.wrong, $0 \[$1-\] } } # Stops the current trivia challenge round and begin a new one after specified break time. alias stop { ^say === Round $trivia.round Question $trivia.quesnum >> Time Limit Expired === ^say The answer to this round was4 $toupper($trivia[A][$trivia.round][$trivia.pick]). if (!trivia.curques) { ^say Correct: } { ^say Correct: $trivia.curqueslist } # If there are wrong answers available, print them out. if (trivia.wrong) { ^say Incorrect: $trivia.wrong } # Decrease the remaining question by one. @trivia.remaining = trivia.remaining - 1 # If we are in final round and there is no more question, announce the final scores and go into # wagering mode. Otherwise set up a timer to show the next question. if ((trivia.round == trivia.MAXROUND) && (trivia.remaining == 0)) { ^timer -refnum 3 $trivia.BREAK /score ^timer -refnum 2 $trivia.WAGERWAIT /start_wager @trivia.active = 0 $calc_penalty() } { ^timer -refnum 2 $trivia.BREAK /show_question } @trivia.active = 0 } # Calculate the penalty for each player by subtracting a fraction of the penalty points off their # total score. alias calc_penalty { foreach trivia.rec ii { @trivia[$trivia[rec][$ii]] = trivia[$trivia[rec][$ii]] - (trivia[$trivia[rec][$ii]][WRONG]/trivia.PENALTYWEIGHT) # If score is less than 0, just keep it at 0. if (trivia[$trivia[rec][$ii]] < 0) { @trivia[$trivia[rec][$ii]] = 0 } } } # Start the wagering process by announcing the start of wagering and waiting $trivia.WAGERTIME. alias start_wager { @trivia.wager = 1 @trivia.round = trivia.MAXROUND + 1 @trivia.remaining = 1 @trivia.quesnum = 0 ^say === Wagering Round For $trivia.channel Trivia === ^say To wager,4 /msg $N !wager where amount is less than or equal to your total score. ^say You have4 $trivia.WAGERTIME seconds to place your wagers. You can also forfeit. ^timer -refnum 5 $trivia.WAGERTIME /stop_wager } # Stops the wagering process by dropping the wager flag and showing the final question. alias stop_wager { # Special form of $show_question causing the timer to call $calc_wager() when the timer expires # instead of the regular $stop(). @trivia.wager = 0 @trivia.wager_special = 1 $show_question(1) } # Clear out the used question list. alias reset_used { @trivia.usedques = [] ^notice $0 The used question list has been reset successfully. } # Display the penalty points for each player. This function also lists out the number of # incorrect answers received from each player. alias penalty { @trivia.temp = 0 if (trivia.current) { ^say === Current Penalty Points === } { ^say How you can expect to see penalties when there are no games going on? } if (trivia.index) { foreach trivia.rec ii { if (trivia[$trivia[rec][$ii]][WRONG]) { @trivia.temp = 1 ^assign trivia.temp2 ${trivia[$trivia[rec][$ii]][WRONG]/trivia.PENALTYWEIGHT} if (trivia.temp2 <= 1 && trivia[$trivia[rec][$ii]][WRONG] <= 1) { ^say $decode($trivia[rec][$ii]) --4 $trivia.temp2 point @4 $trivia[$trivia[rec][$ii]][WRONG] wrong answer } { if (trivia.temp2 <= 1 && trivia[$trivia[rec][$ii]][WRONG] > 1) { ^say $decode($trivia[rec][$ii]) --4 $trivia.temp2 point @4 $trivia[$trivia[rec][$ii]][WRONG] wrong answers } { if (trivia.temp2 > 1 && trivia[$trivia[rec][$ii]][WRONG] <= 1) { ^say $decode($trivia[rec][$ii]) --4 $trivia.temp2 points @4 $trivia[$trivia[rec][$ii]][WRONG] wrong answer } { ^say $decode($trivia[rec][$ii]) --4 $trivia.temp2 points @4 $trivia[$trivia[rec][$ii]][WRONG] wrong answers } } } } } if (!trivia.temp) { if (trivia.current) { ^say No one has been penalized so far. } } } { if (trivia.current) { ^say No one has been penalized so far. } } } # Terminate the trivia program. ($0 == 1 means normal quit; $0 == 0 means abnormal) alias endtrivia { @trivia.winnerscore = 0 if (![$0]) { ^say Abnormal termination of $trivia.channel Trivia program. foreach trivia.rec ii { ^assign -trivia[$trivia[rec][$ii]][WAGER] ^assign -trivia[$trivia[rec][$ii]][WRONG] ^assign -trivia[$trivia[rec][$ii]][LIST] ^assign -trivia[$trivia[rec][$ii]] ^assign -trivia[rec][$ii] } } { # Clear out all player scores according to the global record list. Print out all # the scores, and delete the score variables. ^say === Final Results For $trivia.channel Trivia === if (trivia.index) { foreach trivia.rec ii { if (trivia[$trivia[rec][$ii]] == 0 || trivia[$trivia[rec][$ii]] == 1) { ^say $decode($trivia[rec][$ii]) --4 $trivia[$trivia[rec][$ii]] point } { ^say $decode($trivia[rec][$ii]) --4 $trivia[$trivia[rec][$ii]] points } # Update the top trivia record if the old one has been broken if (trivia[$trivia[rec][$ii]] > trivia.bestscore) { @trivia.bestscore = trivia[$trivia[rec][$ii]] @trivia.bestname = decode($trivia[rec][$ii]) } # Update the top score of the day if the old one has been broken if (trivia[$trivia[rec][$ii]] > trivia.best_day_score) { @trivia.best_day_score = trivia[$trivia[rec][$ii]] @trivia.best_day_name = decode($trivia[rec][$ii]) } # Update the top score of the week if the old one has been broken if (trivia[$trivia[rec][$ii]] > trivia.best_week_score) { @trivia.best_week_score = trivia[$trivia[rec][$ii]] @trivia.best_week_name = decode($trivia[rec][$ii]) } # Update the top score of the month if the old one has been broken if (trivia[$trivia[rec][$ii]] > trivia.best_month_score) { @trivia.best_month_score = trivia[$trivia[rec][$ii]] @trivia.best_month_name = decode($trivia[rec][$ii]) } # Determine the top score of this game if (trivia[$trivia[rec][$ii]] > trivia.winnerscore) { @trivia.winnerscore = trivia[$trivia[rec][$ii]] } } # Now that we know the top score, we check everyone's score against top score # just in case there are ties. We award everyone with top score a game won record. foreach trivia.rec ii { if (trivia[$trivia[rec][$ii]] == trivia.winnerscore) { @trivia.dummvar = auth_help($decode($trivia[rec][$ii]) 3) } ^assign -trivia[$trivia[rec][$ii]][WAGER] ^assign -trivia[$trivia[rec][$ii]][WRONG] ^assign -trivia[$trivia[rec][$ii]][LIST] ^assign -trivia[$trivia[rec][$ii]] ^assign -trivia[rec][$ii] } } { ^say No one managed to score any points during this game. } } # Clear out all the global variables and timers so weird things don't happen. if (trivia.active) { ^timer -delete 1 } { ^timer -delete 2 } @trivia.current = 0 } # Calculate the wager results based on what players wagered. alias calc_wager { @trivia.active = 0 ^say === Round $trivia.round Question $trivia.quesnum >> Time Limit Expired === ^say The answer to this round was4 $toupper($trivia[A][$trivia.round][$trivia.pick]). if (!trivia.curques) { ^say Correct answers: } { ^say Correct answers: $trivia.curqueslist } # If there are wrong answers available, print them out. if (trivia.wrong) { ^say Incorrect answers: $trivia.wrong } if (trivia.index) { foreach trivia.rec ii { if ([$trivia[$trivia[rec][$ii]]]) { # If they got the wagering question correct, add the wager. Otherwise, subtract it. if (trivia[$trivia[rec][$ii]][WAGER]) { if (match($decode($trivia[rec][$ii]) $trivia.curques)) { @trivia[$trivia[rec][$ii]] = trivia[$trivia[rec][$ii]] + trivia[$trivia[rec][$ii]][WAGER] } { @trivia[$trivia[rec][$ii]] = trivia[$trivia[rec][$ii]] - trivia[$trivia[rec][$ii]][WAGER] } } } } } $endtrivia(1) } # Prints out the score of each player whose score is non-zero. alias score { @trivia.temp = [] if (trivia.current) { ^say === Current Scores === if (trivia.index) { foreach trivia.rec ii { if (match($decode($trivia[rec][$ii]) $trivia.temp)) { } { if (trivia[$trivia[rec][$ii]] == 1 || trivia[$trivia[rec][$ii]] == 0) { ^say $decode($trivia[rec][$ii]) --4 $trivia[$trivia[rec][$ii]] point } { ^say $decode($trivia[rec][$ii]) --4 $trivia[$trivia[rec][$ii]] points } ^assign trivia.temp $trivia.temp $decode($trivia[rec][$ii]) } } } { ^say No one managed to score any points so far. } } { ^say How you can expect to see scores when there are no games going on? } } # Function to handle dueling during games. This function is called when a !duel msg is # received by the bot. alias duel { # Duels can only be started when there is a trivia game running, when a person has at least $trivia.DUELMIN # points, and when it's not the last round. if (!trivia.current || trivia[$encode($0)] < trivia.DUELMIN || ( ((trivia.round == trivia.MAXROUND) && (trivia.quesnum > 3)) || (trivia.round > trivia.MAXROUND) ) || trivia.duelwait || match($0 $trivia.duelagg) || match($0 $trivia.duelrestlist)) { if (!trivia.current) { ^notice $0 [ERROR] You cannot issue a duel when no game is going on. } { if (trivia[$encode($0)] < trivia.DUELMIN) { ^notice $0 You need at least $trivia.DUELMIN points to start a duel. } { if (( ((trivia.round == trivia.MAXROUND) && (trivia.quesnum > 3)) || (trivia.round > trivia.MAXROUND) )) { ^notice $0 It is too late in the game to start a duel. Try earlier next time. } { if (trivia.duelwait) { ^notice $0 There is another duel going on right now. Please try later. } { @trivia.temp1 = strip(\~\!\@\#\$\^\&\*\_\+\-\=\[\]\{\}\\\|\;\'\,\.\/\<\>\?\:\"\(\)\% $0) @trivia.temp2 = strip(\~\!\@\#\$\^\&\*\_\+\-\=\[\]\{\}\\\|\;\'\,\.\/\<\>\?\:\"\(\)\% $trivia.duelagg) if (match($trivia.temp1 $trivia.temp2)) { ^notice $0 You cannot initiate two duels at the same time! } { ^notice $0 You have to wait $trivia.DUELREST seconds before you can duel again. } } } } } } { # A person cannot duel with him/herself if (match($0 $1)) { ^say [DUEL] $0 pokes him or herself in the eye with a blazing hot iron bar. } { ^assign trivia.0 $0 ^assign trivia.1 $1 ^userhost $trivia.1 -cmd ^assign trivia.duelvictim $$0 ^userhost $trivia.1 -cmd if ([$3]) { # Certain people like ChanServ cannot be duelled with if (match($trivia.duelvictim $trivia.NODUEL)) { ^notice $trivia.0 [ERROR] You cannot issue a duel to that person. } { # Cannot duel someone with less than $trivia.DUELMIN points if (trivia[$encode($trivia.duelvictim)] < trivia.DUELMIN) { ^notice $trivia.0 You can only duel someone with at least $trivia.DUELMIN points. } { @trivia.taunttemp = rand($trivia.TMAX) + 1 ^say [DUEL] $trivia.0 yells at $trivia.duelvictim, "$trivia[T][$trivia.taunttemp]" @trivia.duelwait = 1 ^assign trivia.duelagg $trivia.0 ^timer -refnum 32 $trivia.DUELSTOPTIME /duelstop ^notice $trivia.duelvictim $trivia.0 wants to duel with you. Accept with /msg $N !acc (no period). } } } { # The requested person to duel with does not exist in the channel ^say [DUEL] $trivia.0 kicks and screams at the wall. } } } } # Function to handle the acceptance of a duel. alias accept_duel { if (!trivia.duelvictim) { ^notice $0 There are no duels going on at this moment. } { if (!match($0 $trivia.duelvictim)) { ^notice $0 Trying to accept another person's duel for them is very unethical. } { if (trivia.duelstart) { ^notice [ERROR] $0 But you have already accepted the duel! } { ^say [DUEL] $trivia.duelvictim shouts back, "$trivia[R][$trivia.taunttemp]" # Set a special flag so the $duelstop() function will not terminate the duel @trivia.duelstart = 1 ^timer -refnum 31 5 /duelques } } } } # Issues the duelling question to both the aggressor and the victim. We choose a question that # corresponds to $trivia.DUELLEVEL. alias duelques { # Set expiration timer for duel question. ^timer -refnum 30 $trivia.DUELQUESTIME /duel_result # Find the maximum number of question available on the current difficulty level and choose # one of them. If the question has been posed already, choose another one. @trivia.duelcatques = trivia[C][$trivia.DUELLEVEL] @trivia.duelpick = rand($trivia.duelcatques) + 1 while ([$match($trivia.DUELLEVEL*$trivia.duelpick $trivia.usedques)]) { @trivia.duelpick = rand($trivia.duelcatques) + 1 } # Add question to used question list. ^assign trivia.usedques $trivia.usedques $trivia.DUELLEVEL*$trivia.duelpick ^assign trivia.temp $trivia[A][$trivia.DUELLEVEL][$trivia.duelpick] ^assign trivia.temp $#trivia.temp if (trivia.temp == 1) { ^notice $trivia.duelagg [DUEL Q] $trivia[Q][$trivia.DUELLEVEL][$trivia.duelpick] \<$trivia.temp word\> ^notice $trivia.duelvictim [DUEL Q] $trivia[Q][$trivia.DUELLEVEL][$trivia.duelpick] \<$trivia.temp word\> } { ^notice $trivia.duelagg [DUEL Q] $trivia[Q][$trivia.DUELLEVEL][$trivia.duelpick] \<$trivia.temp words\> ^notice $trivia.duelvictim [DUEL Q] $trivia[Q][$trivia.DUELLEVEL][$trivia.duelpick] \<$trivia.temp words\> } } # Function to read in the duel answers and process them. For a duel, the first person to answer # correctly wins the duel, but we wait until $duel_result() is called to process the final winner # so we don't end up with concurrency issues in having multiple duels going on. alias duel_ans { if (!trivia.duelvictim) { ^notice $0 There are no duels going on at this moment. } { if (!match($0 $trivia.duelagg) && !match($0 $trivia.duelvictim)) { ^notice $0 You are not participating in the current duel. } { if (match($0 $trivia.duelrightlist)) { ^notice $0 You have already answered the duel challenge correctly! } { @trivia.duelcorrect = match_all(1 $1-) if (trivia.duelcorrect) { ^notice $0 Correct answer for duel -- seeing who answered first... ^assign trivia.duelrightlist $trivia.duelrightlist $0 } { ^notice $0 Sorry, but your answer for the duel challenge is incorrect. } } } } } # Checks the result of a duel and redistributes points accordingly. This function calls $duel_award() # to distribute to the points. alias duel_result { if (!trivia.duelrightlist) { ^say [DUEL] Neither person got the duel question correct. This duel ends in a draw. } { # Find the winner and loser, then send them as parameters into a point changer if (match($word(0 $trivia.duelrightlist) $trivia.duelagg)) { ^timer -refnum 34 1 /duel_award $trivia.duelagg $trivia.duelvictim } { ^timer -refnum 34 1 /duel_award $trivia.duelvictim $trivia.duelagg } } # Add both the aggressor and the victim to the resting list so they cannot start another duel right away ^assign trivia.duelrestlist $trivia.duelagg $trivia.duelvictim ^timer -refnum 33 $trivia.DUELREST /duel_rest_reset @trivia.duelwait = 0 @trivia.duelcorrect = 0 @trivia.duelstart = 0 @trivia.duelrightlist = [] @trivia.duelvictim = [] @trivia.duelagg = [] } # Resets the duel resting list so the victim and aggressor and initiate a duel again. alias duel_rest_reset { @trivia.duelrestlist = [] } # This function awards the winner of the duel challenge a certain percentage of the loser's scores. # The first parameter is the winner and the second is the loser. alias duel_award { @trivia.tempaward = trivia[$encode($1)] / trivia.DUELFRAC @trivia[$encode($0)] = trivia[$encode($0)] + trivia.tempaward @trivia[$encode($1)] = trivia[$encode($1)] - trivia.tempaward if (trivia.tempaward == 1) { ^say [DUEL] $0 has plundered4 $trivia.tempaward point from $1. } { ^say [DUEL] $0 has plundered4 $trivia.tempaward points from $1. } @trivia.dummvar = auth_help($0 1) @trivia.dummvar = auth_help($1 2) } # Stops a duel if the duel victim does not respond in a limited amount of time. This function # will not perform its duty if $trivia.duelstart is set. alias duelstop { if (!trivia.duelstart) { ^say [DUEL] $trivia.duelvictim did not respond to $trivia.duelagg's duel request. @trivia.duelwait = 0 @trivia.duelvictim = [] @trivia.duelagg = [] } @trivia.duelstart = 0 } # Authorizes a player to modify their own personal stat database. alias check_auth { if (!trivia.stat_loaded) { /load $PP.SAVEFILE } if (trivia[AUTH][$encode($0)]) { ^notice $0 You have already been authenticated. } { if (trivia[PASS][$encode($0)] == [$1-]) { @trivia[AUTH][$encode($0)] = 1 ^notice $0 You have been successfully authenticated! } { if (!trivia[PASS][$encode($0)]) { ^notice $0 [ERROR] Sorry, but there are no records of you in the database. } { ^notice $0 [ERROR] That is not the correct password. Please try again. } } } } # Deauthorizes a player from modifying their own personal stat database. alias deauth { if (!trivia[AUTH][$encode($0)]) { ^notice $0 [ERROR] You have not been authenticated! } { ^assign -trivia[AUTH][$encode($0)] ^notice $0 Your authentication has been successfully removed. } } # Lets a user changes their personal stat password. Passwords cannot be blank and cannot # contain characters which are not assignable. alias change_pass { if (!trivia[PASS][$encode($0)]) { ^notice $0 [ERROR] You do not have an account in the database! } { if (trivia[PASS][$encode($0)] != [$1]) { ^notice $0 [ERROR] The old password is incorrect. Please try again. } { if (strip(\~\!\@\#\$\^\&\*\_\+\-\=\[\]\{\}\\\|\;\'\,\.\/\<\>\?\:\"\(\)\% $2) != [$2]) { ^notice $0 Your password may only contain alphanumerical choices. } { @trivia[PASS][$encode($0)] = [$2] ^notice $0 Your password has been changed successfully. } } } } # Function to ask people for authorization when a change in their personal stat database is # required. The parameter $0 is the nickname of the person being authorized, and $1 is a # control variable that determines what stat to change (0: RIGHT, 1: DUEL_WIN, 2: DUEL_LOSE, # 3: GAME_WON 4:WRONG). alias auth_help { @function_return = 1 if ([$1] == 0) { @trivia.type = [RIGHT] } { if ([$1] == 1) { @trivia.type = [DUEL_WIN] } { if ([$1] == 2) { @trivia.type = [DUEL_LOSE] } { if ([$1] == 3) { @trivia.type = [GAME_WON] } { if ([$1] == 4) { @trivia.type = [WRONG] } } } } } # Check whether the person has authenticated with us. If not, keep track of regular game # score but do not modify the personal stat database to prevent fraud. if ((trivia[PASS][$encode($0)] != []) && !trivia[AUTH][$encode($0)]) { ^notice $0 Authenticate with /msg $N !auth to have stats updated. } { if (!trivia[PASS][$encode($0)]) { # Attach a random number to their nick as the starting password. No password # implies that this person is a new player, as passwords cannot be empty. @trivia.temp = rand(10000) @trivia.temp = [$0]##trivia.temp ^notice $0 New player with default password "$trivia.temp". Change it using /msg $N !change_pass . @trivia[AUTH][$encode($0)] = 1 @trivia[PASS][$encode($0)] = trivia.temp @trivia[$trivia.type][$encode($0)] = 1 } { if ([$1] != 4) { @trivia[$trivia.type][$encode($0)] = trivia[$trivia.type][$encode($0)] + 1 } { @trivia[$trivia.type][$encode($0)] = trivia[$trivia.type][$encode($0)] + [$2] } } } } # Checks to see whether $0 has any points. If so, we move all those points to $1 and delete # the original record. Otherwise, just ignore the event. alias update_name { # Process nickname change only if they have score ­ 0 if (trivia[$encode($0)]) { # Transfer points over to new nick @trivia[$encode($1)] = trivia[$encode($0)] @trivia.dummy = addtolist($1 0) # Delete old nick so it's not displayed ^assign -trivia[$encode($0)][WAGER] ^assign -trivia[$encode($0)][WRONG] ^assign -trivia[$encode($0)][LIST] ^assign -trivia[$encode($0)] # Delete them from the record list also if (trivia.index) { foreach trivia.rec ii { if (match($encode($0) $trivia[rec][$ii])) { ^assign -trivia[rec][$ii] } } } } } # Converts a given amount of questions into an appropriate title alias q_to_title { # If they have own title and rank is high enough, use that instead @trivia.tempnet = trivia[RIGHT][$encode($1)] - trivia[WRONG][$encode($1)] / trivia.PENALTYWEIGHT if (trivia[SELF_TITLE][$encode($1)] != [] && trivia.tempnet >= trivia.MAXRANK) { @function_return = [6$trivia[SELF_TITLE][$encode($1)]] } { if ([$0] < 0) { @function_return = [Court Jester] } { if ([$0] < 10) { @function_return = [Lowly Slime Mold] } { if ([$0] < 20) { @function_return = [Growing Slime Mold] } { if ([$0] < 30) { @function_return = [Regular Slime Mold] } { if ([$0] < 40) { @function_return = [Strong Slime Mold] } { if ([$0] < 50) { @function_return = [Slime Mold Master] } { if ([$0] < 60) { @function_return = [Smelly Fungus] } { if ([$0] < 70) { @function_return = [Fresh Fungus] } { if ([$0] < 80) { @function_return = [Kawaii Fungus] } { if ([$0] < 90) { @function_return = [Buffy Fungus] } { if ([$0] < 100) { @function_return = [Fungus Master] } { if ([$0] < 110) { @function_return = [Weak Peon] } { if ([$0] < 120) { @function_return = [Confused Peon] } { if ([$0] < 130) { @function_return = [Ordinary Peon] } { if ([$0] < 140) { @function_return = [Cheerful Peon] } { if ([$0] < 150) { @function_return = [Powerful Peon] } { if ([$0] < 160) { @function_return = [Poor Mercenary] } { if ([$0] < 170) { @function_return = [Lower Class Mercenary] } { if ([$0] < 180) { @function_return = [Middle Class Mercenary] } { if ([$0] < 190) { @function_return = [Upper Class Mercenary] } { if ([$0] < 200) { @function_return = [Mercenary Guildmaster] } { @function_return = q_to_title_2($0) }}}}}}}}}}}}}}}}}}}}}} } # Converts a given amount of questions into an appropriate title alias q_to_title_2 { if ([$0] < 210) { @function_return = [Apprentice Footman] } { if ([$0] < 220) { @function_return = [Advancing Footman] } { if ([$0] < 230) { @function_return = [Skilled Footman] } { if ([$0] < 240) { @function_return = [Advanced Footman] } { if ([$0] < 250) { @function_return = [Footman Squad Leader] } { if ([$0] < 260) { @function_return = [Unwieldly Thief] } { if ([$0] < 270) { @function_return = [Average Thief] } { if ([$0] < 280) { @function_return = [Skilled Thief] } { if ([$0] < 290) { @function_return = [Very Stealthy Thief] } { if ([$0] < 300) { @function_return = [Master Shadow Thief] } { if ([$0] < 310) { @function_return = [Weak Archer] } { if ([$0] < 320) { @function_return = [Copper Archer] } { if ([$0] < 330) { @function_return = [Silver Archer] } { if ([$0] < 340) { @function_return = [Gold Archer] } { if ([$0] < 350) { @function_return = [Platinum Archer] } { if ([$0] < 360) { @function_return = [Practicing Knight] } { if ([$0] < 370) { @function_return = [Trained Knight] } { if ([$0] < 380) { @function_return = [Skillful Knight] } { if ([$0] < 390) { @function_return = [Silver Knight] } { if ([$0] < 400) { @function_return = [Golden Knight] } { @function_return = [6God of Trivia] }}}}}}}}}}}}}}}}}}}} } # Given a person's nickname, this function reports the number of correct answers # they've given. alias report_stat { # Load the stat file if not loaded yet. if (!trivia.stat_loaded) { /load $PP.SAVEFILE } if (!trivia[PASS][$encode($0)]) { ^say There are no record of 5$0 in the database. } { # Calculate the "net" correct answer using RIGHT - WRONG/PENALTYWEIGHT @trivia.tempnet = trivia[RIGHT][$encode($0)] - trivia[WRONG][$encode($0)] / trivia.PENALTYWEIGHT if (trivia[GAME_WON][$encode($0)] > 25) { if (!trivia.tempnet) { ^say \>\> Stats for Lord $0 the 2$q_to_title($trivia.tempnet $0) \(0\) } { ^say \>\> Stats for Lord $0 the 2$q_to_title($trivia.tempnet $0) \($trivia.tempnet\) } } { if (!trivia.tempnet) { ^say \>\> Stats for $0 the 2$q_to_title($trivia.tempnet $0) \(0\) } { ^say \>\> Stats for $0 the 2$q_to_title($trivia.tempnet $0) \($trivia.tempnet\) } } @trivia.temp = [\>\> 4Duel: ] if (!trivia[DUEL_WIN][$encode($0)]) { @trivia.temp = trivia.temp##[0] } { @trivia.temp = trivia.temp##[$trivia[DUEL_WIN][$encode($0)]] } if (!trivia[DUEL_WIN][$encode($0)] || (trivia[DUEL_WIN][$encode($0)] == 1)) { @trivia.temp = trivia.temp##[ Win,] } { @trivia.temp = trivia.temp##[ Wins,] } if (!trivia[DUEL_LOSE][$encode($0)]) { @trivia.temp = trivia.temp##[ 0] } { @trivia.temp = trivia.temp##[ $trivia[DUEL_LOSE][$encode($0)]] } if (!trivia[DUEL_LOSE][$encode($0)] || (trivia[DUEL_LOSE][$encode($0)] == 1)) { @trivia.temp = trivia.temp##[ Loss 4Game: ] } { @trivia.temp = trivia.temp##[ Losses 4Game: ] } if (!trivia[GAME_WON][$encode($0)]) { @trivia.temp = trivia.temp##[0] } { @trivia.temp = trivia.temp##[$trivia[GAME_WON][$encode($0)]] } if (!trivia[GAME_WON][$encode($0)] || (trivia[GAME_WON][$encode($0)] == 1)) { @trivia.temp = trivia.temp##[ Domination] } { @trivia.temp = trivia.temp##[ Dominations] } ^say $trivia.temp } } # Converts the personal data from one nickname to another nickname. $0 is the new nick, # $1 is the old nick, and $2 is the password. alias check_conv { if (!trivia[PASS][$encode($1)]) { ^notice $0 [ERROR] Old personal stat information does not exist! } { if (trivia[PASS][$encode($1)] != [$2]) { ^notice $0 [ERROR] The password you supplied is incorrect. Please try again. } { if ([$0] == [$1]) { ^notice $0 The personal stat information is already under your name! } { if (trivia[PASS][$encode($0)]) { ^notice $0 There is already a set of stat under $0 which cannot be overrided. } { ^notice $0 Your personal stat information has been transferred into 5$0's authority. @trivia[PASS][$encode($0)] = trivia[PASS][$encode($1)] ^assign -trivia[PASS][$encode($1)] if (trivia[RIGHT][$encode($1)]) { @trivia[RIGHT][$encode($0)] = trivia[RIGHT][$encode($1)] ^assign -trivia[RIGHT][$encode($1)] } if (trivia[DUEL_WIN][$encode($1)]) { @trivia[DUEL_WIN][$encode($0)] = trivia[DUEL_WIN][$encode($1)] ^assign -trivia[DUEL_WIN][$encode($1)] } if (trivia[DUEL_LOSE][$encode($1)]) { @trivia[DUEL_LOSE][$encode($0)] = trivia[DUEL_LOSE][$encode($1)] ^assign -trivia[DUEL_LOSE][$encode($1)] } if (trivia[WRONG][$encode($1)]) { @trivia[WRONG][$encode($0)] = trivia[WRONG][$encode($1)] ^assign -trivia[WRONG][$encode($1)] } if (trivia[GAME_WON][$encode($1)]) { @trivia[GAME_WON][$encode($0)] = trivia[GAME_WON][$encode($1)] ^assign -trivia[GAME_WON][$encode($1)] } # Convert high score variables to new nickname too. if (trivia[bestname] == [$1]) { @trivia[bestname] = [$0] } if (trivia[best_day_name] == [$1]) { @trivia[best_day_name] = [$0] } if (trivia[best_week_name] == [$1]) { @trivia[best_week_name] = [$0] } if (trivia[best_month_name] == [$1]) { @trivia[best_month_name] = [$0] } } } } } } # Resets the time stamp for the high score variables like score of the day, score of the # week, score of the month, score of the year. The $0 parameter determines which record to # reset (0:DAY 1:WEEK 2:MONTH). alias time_reset { @function_return = 1 if ([$0] == 0) { @trivia.timestamp_day = time() @trivia.best_day_name = [None] @trivia.best_day_score = 0 } if ([$0] == 1) { @trivia.timestamp_week = time() @trivia.best_week_name = [None] @trivia.best_week_score = 0 } if ([$0] == 2) { @trivia.timestamp_month = time() @trivia.best_month_name = [None] @trivia.best_month_score = 0 } } # Determines whether the high score variables need to be reset. alias update_high { @function_return = 1 @trivia.timecurr = time() # Reset score of the day after 24 hours if (trivia.timecurr - trivia.timestamp_day > 86400) { @trivia.dummvar = time_reset(0) } # Reset score of the week after 7 days if (trivia.timecurr - trivia.timestamp_week > 604800) { @trivia.dummvar = time_reset(1) } # Reset score of the month after 30 days if (trivia.timecurr - trivia.timestamp_month > 2592000) { @trivia.dummvar = time_reset(2) } } # Reports the high score record for the day. alias report_day { # Load the stat file if not loaded yet. if (!trivia.stat_loaded) { /load $PP.SAVEFILE } if (trivia.best_day_name == [None]) { ^say \>\> 4Daily High Score: } { @trivia.tempnet = trivia[RIGHT][$encode($trivia.best_day_name)] - trivia[WRONG][$encode($trivia.best_day_name)] / trivia.PENALTYWEIGHT ^say \>\> 4Daily High Score: $trivia.best_day_score by $trivia.best_day_name } } # Reports the high score record for the week. alias report_week { # Load the stat file if not loaded yet. if (!trivia.stat_loaded) { /load $PP.SAVEFILE } if (trivia.best_week_name == [None]) { ^say \>\> 4Weekly High Score: } { @trivia.tempnet = trivia[RIGHT][$encode($trivia.best_week_name)] - trivia[WRONG][$encode($trivia.best_week_name)] / trivia.PENALTYWEIGHT ^say \>\> 4Weekly High Score: $trivia.best_week_score by $trivia.best_week_name } } # Reports the high score record for the month. alias report_month { # Load the stat file if not loaded yet. if (!trivia.stat_loaded) { /load $PP.SAVEFILE } if (trivia.best_month_name == [None]) { ^say \>\> 4Monthly High Score: } { @trivia.tempnet = trivia[RIGHT][$encode($trivia.best_month_name)] - trivia[WRONG][$encode($trivia.best_month_name)] / trivia.PENALTYWEIGHT ^say \>\> 4Monthly High Score: $trivia.best_month_score by $trivia.best_month_name } } # Shutdown routine for the bot. This will save the critical variables and then quit IRC. alias shutdown { /sve /quit } # Save routine for storing various statistical variables for the trivia script. This # routine has been "stolen" from the PurePak script. Credit is hereby given. alias sve { if (!(HOME)) { exec -name rm $PP.SET.RMCMD $PP.SAVEFILE echo *** Warning: Your home directory could not be determined. Your saved settings file will be saved to the current working directory. If this isn't your home directory, PurePak may not be able to find it's saved settings file at startup! } {/exec -name rm $PP.SET.RMCMD ${HOME}/$PP.SAVEFILE} wait -CMD %rm if (1) { if (PP.EPIC) { if (!(HOME)) {@ FHANDLE = open($PP.SAVEFILE w)} {@ FHANDLE = open(${HOME}/$PP.SAVEFILE w)} if (FHANDLE > 0) {/EVAL ^assign WM /write $FHANDLE} { echo *** Could not open target file! @ WM = [/comment] } } { @ WM = [/xecho -WINDOW WRITEOUT] ^window new ^window log_extrainfo off ^window hold_mode off ^window name WRITEOUT if (!(HOME)) {^window logfile $PP.SAVEFILE} {^window logfile ${HOME}/$PP.SAVEFILE} ^window log on } $WM # Trivia version $trivia.VERSION saved settings file $WM # Written $stime($time()) $WM @trivia.dummvar = save_help($WM) $WM # Player personal stat passwords foreach trivia.PASS ii { $WM @ trivia[PASS][$ii] = [$trivia[PASS][$ii]] } $WM $WM # Number of questions player got right foreach trivia.RIGHT ii { $WM @ trivia[RIGHT][$ii] = [$trivia[RIGHT][$ii]] } $WM $WM # Number of questoins player got wrong foreach trivia.WRONG ii { $WM @ trivia[WRONG][$ii] = [$trivia[WRONG][$ii]] } $WM $WM # Number of duels player won foreach trivia.DUEL_WIN ii { $WM @ trivia[DUEL_WIN][$ii] = [$trivia[DUEL_WIN][$ii]] } $WM $WM # Number of duels player lost foreach trivia.DUEL_LOSE ii { $WM @ trivia[DUEL_LOSE][$ii] = [$trivia[DUEL_LOSE][$ii]] } $WM $WM # Number of trivia games player won foreach trivia.GAME_WON ii { $WM @ trivia[GAME_WON][$ii] = [$trivia[GAME_WON][$ii]] } $WM $WM # Customized titles for players foreach trivia.SELF_TITLE ii { $WM @ trivia[SELF_TITLE][$ii] = [$trivia[SELF_TITLE][$ii]] } $WM $WM echo *** Saved settings loaded from ${PP.SAVEFILE} if (match(*xecho* $WM)) { ^window log off ^window kill } { comment $close($FHANDLE) ^assign -FHANDLE } ^assign -WM echo *** Current settings saved to ${PP.SAVEFILE} } } # Help function of the save alias. alias save_help { $0 # Flag to indicate loading of stat file $0 @ trivia[stat_loaded] = [1] $0 $0 # Random seeding value $0 @ trivia[randomvar] = [$trivia[randomvar]] $0 $0 # Top trivia score holder $0 @ trivia[bestname] = [$trivia[bestname]] $0 @ trivia[bestscore] = [$trivia[bestscore]] $0 $0 # Daily high score variables $0 @ trivia[timestamp_day] = [$trivia[timestamp_day]] $0 @ trivia[best_day_name] = [$trivia[best_day_name]] $0 @ trivia[best_day_score] = [$trivia[best_day_score]] $0 $0 # Weekly high score variables $0 @ trivia[timestamp_week] = [$trivia[timestamp_week]] $0 @ trivia[best_week_name] = [$trivia[best_week_name]] $0 @ trivia[best_week_score] = [$trivia[best_week_score]] $0 $0 # Monthly high score variables $0 @ trivia[timestamp_month] = [$trivia[timestamp_month]] $0 @ trivia[best_month_name] = [$trivia[best_month_name]] $0 @ trivia[best_month_score] = [$trivia[best_month_score]] $0 } # Displays the current scores when people type in !trivia_score in the main channel. on -public "* * !trivia score" { ^timer 1 /score } # Displays the current penalty points. on -public "* * !trivia penalty" { ^timer 1 /penalty } # Start a new game of trivia on -public "* * !trivia start" { ^timer 1 /trivia } # Help system which private notices a help menu to people who type !help in the channel. on -public "* * !help" { ^notice $0 Please type4 !help in the trivia channel to receive help: ^notice $0 01. General info: copyright, general, record, score, start_game, stat ^notice $0 02. Special features: daily_double, duel, fun, penalty ^notice $0 03. Stat related: auth, change_pass, convert, title, title_kill, unauth ^notice $0 04. Admin control: add, load_q, load_s, reset, save, start, stop, sub, wipe } # General information help system on -public "* * !help copyright" { ^notice $0 The full content of this script as well auxilary support files are copyrights of Bernard Yen. You are allowed to modify and distribute the script on a non-profit basis, but changes must be clearly stated and not misrepresented as the original. } on -public "* * !help general" { ^notice $0 Welcome to $trivia.channel Trivia. There are $trivia.MAXROUND rounds every game, each consisting of $trivia.QU.1 questions, followed by a wagering round where you can potentially double your score. Points are allocated as $trivia.P.1, $trivia.P.2, $trivia.P.3, and $trivia.P.4 respectively for the $trivia.MAXROUND rounds. Approximately 2 questions per game are daily double questions that carry both greater award and penalty. To answer, simply /msg $N using your IRC client. } on -public "* * !help record" { ^notice $0 The record of your gameplay is kept in a personal stat database. This can be accessed by typing !stat in the channel where nick is case sensitive. In addition, you can access the high score of the day, week, and month by typing !trivia day, !trivia week, and !trivia month respectively into the trivia channel. } on -public "* * !help score" { ^notice $0 The current list of scores achieved by players can be viewed by typing !trivia score into the trivia channel. Penalties are not subtracted until right before the wagering round starts. } on -public "* * !help start_game" { ^notice $0 You can start a game of trivia at any time by typing !trivia start into the trivia channel, but please note that only an admin can stop the game while it is in progress. } on -public "* * !help stat" { ^notice $0 You can view any player's personal stat database by typing !stat into the trivia channel where nick is a case sensitive nickname. } # Special features help system on -public "* * !help daily_double" { ^notice $0 Every game, there are approximately 2 questions that will have "daily double" after them. Getting those correct will give you double the normal points, but getting them incorrect will cause you to lose half of what the round is worth. If the round is normally worth 2 points, you could potentially gain 4 points or lose 2 points per guess. } on -public "* * !help duel" { ^notice $0 You can now challenge another person to a duel using /msg $N !duel and potentially plunder 30% of their points. Duelling is enabled when you have at least $trivia.DUELMIN points, the game isn't about to end, and there isn't another duel going on. To answer a duel, use /msg $N !ans . After a duel, you must wait $trivia.DUELREST seconds before you can start another one. } on -public "* * !help fun" { ^notice $0 You can now submit funny or plain wrong answers to show other players your creative juice without getting penalized. Simply message the bot with /msg $N !fun and it will be added. } on -public "* * !help penalty" { ^notice $0 To alleviate cheating and random guessing, incorrect answers are now penalized. Penalty is based on the length of your answer submission divided by the length of the actual answer. If the answer is "triviabot rules" and you type "triviabot is really stupid", you will get penalized (4/2) / $trivia.PENALTYWEIGHT = 0.4 points. At the end, penalty points are added and rounded down. } # Stat commands help system on -public "* * !help auth" { ^notice $0 By typing /msg $N !auth you unlock your personal stat database and allow changes to it. You must do this only when the bot first enters the channel or if you used the !unauth command earlier. } on -public "* * !help change_pass" { ^notice $0 By typing /msg $N !change_pass you can change your password from to . } on -public "* * !help convert" { ^notice $0 By typing /msg $N !convert you can convert your personal stat database from the old nick and move it onto your current nick. This is handy if you have many different nicknames but want your stats to follow you. } on -public "* * !help title" { ^notice $0 By typing /msg $N !title after you reach a rank of at least $trivia.MAXRANK, you will be able to create a customized title for your personal stat database display. } on -public "* * !help title_kill" { ^notice $0 By typing /msg $N !title_kill you can delete your customized title. } on -public "* * !help unauth" { ^notice $0 By typing /msg $N !unauth when you want to leave the channel, you lock your personal stat database and prevent further changes to it. } # Admin control help system #^notice $0 04. Admin commands: add, load_q, load_s, reset, save, start, stop, sub, wipe on -public "* * !help add" { ^notice $0 By typing /msg $N !add <adm_pass> <nick> <pts> you can add points to a specified player. } on -public "* * !help load_q" { ^notice $0 By typing /msg $N !load_q <adm_pass> you can reload the question file. This is useful if you modified the question file while a game is running and want new questions to show up. } on -public "* * !help load_s" { ^notice $0 By typing /msg $N !load_s <adm_pass> you can reload the script file. Do not do this while a game is running or else weird things might happen. } on -public "* * !help reset" { ^notice $0 By typing /msg $N !reset <adm_pass> you can reset the used question list. } on -public "* * !help save" { ^notice $0 By typing /msg $N !save <adm_pass> you can save trivia variables to the file. Please note that this is currently buggy and may cause unexpected crashes. } on -public "* * !help start" { ^notice $0 By typing /msg $N !start <adm_pass> you can start a game of trivia. } on -public "* * !help stop" { ^notice $0 By typing /msg $N !stop <adm_pass> you can stop a game of trivia. } on -public "* * !help sub" { ^notice $0 By typing /msg $N !sub <adm_pass> <nick> <pts> you can subtract points from a specified player. } on -public "* * !help wipe" { ^notice $0 By typing /msg $N !wipe <adm_pass> <nick> where nick is a case sensitive nickname, you can wipe the personal stat database of the specified player. } # Hook to detect changes in nickname so we can update the score database so the points # will move with the person. on -channel_nick "* * *" { ^timer 1 /update_name $1 $2 } # Process trivia statistic queries. on -public "* * !stat %" { ^timer 1 /report_stat $word(1 $2-) } on -public "* * !trivia day" { ^timer 1 /report_day } on -public "* * !trivia week" { ^timer 1 /report_week } on -public "* * !trivia month" { ^timer 1 /report_month }